package com.example.personnel_management_system.util;

import java.io.Serializable;

public class Result<T> implements Serializable {
    private Integer status;
    private String  message;
    private T data;

    public static <T>Result<T>success(T data){
        return new Result<>(200,"true",data);
    }

    public  static <T>Result<T>success(){
        return new Result<>(200,"true",null);
    }
    public static <T>Result<T>failure(){
        return new Result<>(401,"false",null);
    }
    public static <T>Result<T>failure(T data){
        return new Result<>(401,"false",data);
    }
    public Result() {
    }
    public Result(Integer status, String message, T data) {
        this.status = status;
        this.message = message;
        this.data = data;
    }
    public Result(Throwable e) {
        // 获取异常对象中的异常信息
        this.message = e.getMessage();
    }
    public Result(Integer status) {
        this.status = status;
    }

    public Result(String message) {
        this.message = message;
    }

    public Result(T data) {
        this.data = data;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
